home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
MM3Tp.sea Folder
/
Made by Marksman
/
Sources
/
mm
/
mmW_Floating_window.p
< prev
next >
Wrap
Text File
|
1994-01-16
|
12KB
|
422 lines
Unit mmW_Floating_window;
{ mmW_Floating_window Handle this Window }
{ Copyright © 1994 George R. Cossey }
{
File name: mmW_Floating_window
Function: Handle a Window
History: 1/16/94 Original by George Cossey
}
interface
uses
Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo,
{}
mmPA_My_Alert,
{}
mmD_My_Modal,
{}
mmMD_My_Movable_Moda,
mmMD_My_Modeless,
mmMD_About_Demo,
{}
UFloating_window;
procedure Init_Floating_window;
procedure Close_Floating_window(whichWindow:WindowPtr);
procedure Resized_Floating_window(OldRect:Rect;whichWindow:WindowPtr);
procedure Update_Floating_window(whichWindow:WindowPtr);
procedure Open_Floating_window;
procedure Activate_Floating_window(whichWindow:WindowPtr;Do_An_Activate:Boolean);
procedure Do_Floating_window(var myEvent:EventRecord);
{ ======================================================= }
{ ======================================================= }
implementation
{ ======================================================= }
{ ======================================================= }
procedure InitRecord(theWS:Floating_windowPRec);
begin
theWS^.theWindow := nil; { Make sure other routines know we are not valid yet }
{ Set the window back color }
theWS^.WindowBackColor.red := $FFFF;
theWS^.WindowBackColor.green := $FFFF;
theWS^.WindowBackColor.blue := $FFFF;
theWS^.Enable_Tool_palette2 := true; { Palette, Tool palette }
theWS^.Value_Tool_palette2 := 0;
U_InitFloating_windowRec(theWS); { Call user init routine }
end;
{ ======================================================= }
procedure LocateInstance(theWindow:WindowPtr);
var
ckWS,theWS:Floating_windowPRec;
begin
theWS := nil; { Init to not found }
ckWS := ListRecPtr_Floating_window;
while (ckWS <> nil) do
begin
if (ckWS^.theWindow = theWindow) then
theWS := ckWS;
ckWS := ckWS^.Next;
end;
RecPtr_Floating_window := theWS;
end;
{ ======================================================= }
{ Routine: Init_Floating_window }
{ Purpose: Initialize our window data to not in use yet }
procedure Init_Floating_window;
begin
theWindowLocRec.Loc_Floating_window.h := 24; { Set default Horz position }
theWindowLocRec.Loc_Floating_window.v := 45; { Set default Vert position }
RecPtr_Floating_window := nil; { No open windows yet }
ListRecPtr_Floating_window := nil;
MultipleAllowed_Floating_window := true; { Init to allow multiple instances }
U_InitFloating_window; { Call the user window init routine }
end;
{ ======================================================= }
{ Routine: Close_Floating_window }
{ Purpose: Close out the window }
procedure Close_Floating_window(whichWindow:WindowPtr);
var
ckWS,theWS:Floating_windowPRec;
begin
if (whichWindow = WindowPtr(-1)) then
whichWindow := FrontWindow;
LocateInstance(whichWindow);
{ See if we should close this window }
if (RecPtr_Floating_window <> nil) then
begin
theWS := RecPtr_Floating_window;
U_CloseFloating_window(theWS); { Call the user window close routine }
SetPort(whichWindow); { Select our window }
theWindowLocRec.Loc_Floating_window.h := 0; { Reset Horz position }
theWindowLocRec.Loc_Floating_window.v := 0; { Reset Vert position }
LocalToGlobal(theWindowLocRec.Loc_Floating_window); { Get global location }
Mk_CloseLayeredWindow(whichWindow); { Notify the layer code that we are closing }
DisposeWindow(whichWindow); { Clear window and controls }
ckWS := ListRecPtr_Floating_window;
if (ckWS = theWS) then { See if first in the list }
begin
ListRecPtr_Floating_window := theWS^.Next; { Use second one as new first }
DisposePtr(Ptr(theWS)); { Get rid of this one }
end
else
begin
while (ckWS <> nil) do { Loop thru them all }
begin
if (ckWS^.Next = theWS) then { See if the next one is a match }
begin
ckWS^.Next := theWS^.Next; { Get new next one }
DisposePtr(Ptr(theWS)); { Get rid of this one }
ckWS := nil; { Get us out of the loop }
end
else
ckWS := ckWS^.Next; { Try the next one }
end;
end;
RecPtr_Floating_window := nil; { No active one }
end;
end;
{ ======================================================= }
{ Routine: Resized_Floating_window }
{ Purpose: We were resized or zoomed, update the scrolling scrollbars }
procedure Resized_Floating_window(OldRect:Rect;whichWindow:WindowPtr);
var
SavePort:WindowPtr; { Place to save the last port }
temp2Rect:Rect; { temp rectangle }
Index:integer; { temp integer }
ScrollHandle:ControlHandle;
theWS:Floating_windowPRec;
begin
LocateInstance(whichWindow);
if (RecPtr_Floating_window <> nil) then { Only do if the window is us }
begin
theWS := RecPtr_Floating_window;
GetPort(SavePort); { Save the current port }
SetPort(whichWindow); { Set the port to my window }
U_ResizedFloating_window(theWS,OldRect); { Call the user window resized routine }
SetPort(SavePort); { Restore the old port }
end;
end;
{ ======================================================= }
{ Routine: Update_Floating_window }
{ Purpose: Update our window }
procedure Update_Floating_window(whichWindow:WindowPtr);
var
SavePort:WindowPtr; { Place to save the last port }
Saved_ForeColor:RGBColor; { Place to save colors }
Saved_BackColor:RGBColor; { Place to save colors }
DrawingColor:RGBColor; { Place to make colors }
theWS:Floating_windowPRec;
begin
LocateInstance(whichWindow);
if (RecPtr_Floating_window <> nil) then { Only do if the window is us }
begin
theWS := RecPtr_Floating_window;
GetPort(SavePort); { Save the current port }
SetPort(whichWindow); { Set the port to my window }
if (Has.ColorQD) then { See if color QuickDraw is around }
begin
GetForeColor(Saved_ForeColor); { Save the fore color }
GetBackColor(Saved_BackColor); { Save the back color }
RGBForeColor(Black_ForeColor); { Set the fore color to Black }
RGBBackColor(White_BackColor); { Set the back color to White }
end; { End of IF }
if (Has.ColorQD) then { See if color QuickDraw is around }
begin
RGBForeColor(Saved_ForeColor); { Restore the fore color }
RGBBackColor(Saved_BackColor); { Restore the back color }
end;
TextFont(applFont); { Back to the application font }
TextSize(12); { Back to the application size }
TextFace([]); { Set text style }
U_UpdateFloating_window(theWS); { Call the user window update routine }
SetPort(SavePort); { Restore the old port }
end;
end;
{ ======================================================= }
{ Routine: Open_Floating_window }
{ Purpose: Open our window }
procedure Open_Floating_window;
var
BehindWindow:WindowPtr; { Used for window placement }
theLong:longint; { Used for icons and hotspots definition }
DefaultPosition:Point; { Used for window placement }
theWS:Floating_windowPRec;
begin
if ((ListRecPtr_Floating_window = nil) or (MultipleAllowed_Floating_window)) then
begin
theWS := Floating_windowPRec(NewPtrClear(sizeof(Floating_windowRec)));
RecPtr_Floating_window := theWS;
theWS^.Next := ListRecPtr_Floating_window;
ListRecPtr_Floating_window := theWS;
InitRecord(theWS);
BehindWindow := Mk_BehindWindow(6); { Get which window to place below }
if (Has.ColorQD) then { See if color QuickDraw is around }
theWS^.theWindow := GetNewCWindow(ResW_Floating_window,nil,BehindWindow) { Get the COLOR window from the resource file }
else
theWS^.theWindow := GetNewWindow(ResW_Floating_window,nil,BehindWindow);{ Get the window from the resource file }
Mk_RegisterWindow(theWS^.theWindow,6); { Register the window with the layers }
SetPort(theWS^.theWindow); { Prepare to write into our window }
{ Make a Palette }
theWS^.Ctrl_Tool_palette2 := MakePalette(theWS^.theWindow,ResC_Tool_palette2,
theWS^.Enable_Tool_palette2,10,2,ResC_N_Tool_palette2,6);
SetPort(theWS^.theWindow); { Select our window }
DefaultPosition.h := 0; { Reset Horz position }
DefaultPosition.v := 0; { Reset Vert position }
LocalToGlobal(DefaultPosition); { Get global location }
PositionWindow(theWS^.theWindow,theWindowLocRec.Loc_Floating_window,DefaultPosition);
U_OpenFloating_window(theWS); { Call the users window open routine }
ShowWindow(theWS^.theWindow); { Show the window now }
end
else
theWS := ListRecPtr_Floating_window;
Mk_HiliteWindow(theWS^.theWindow); { Already open, so show it }
end;
{ ======================================================= }
{ Routine: Activate_Floating_window }
{ Purpose: We activated or deactivated }
procedure Activate_Floating_window(whichWindow:WindowPtr;Do_An_Activate:Boolean);
var
SavePort:WindowPtr; { Place to save the last port }
theWS:Floating_windowPRec;
begin
LocateInstance(whichWindow);
if (RecPtr_Floating_window <> nil) then { Only do if the window is us }
begin
theWS := RecPtr_Floating_window;
GetPort(SavePort); { Save the current port }
SetPort(whichWindow); { Set the port to my window }
if (not(Do_An_Activate)) then { Handle the deactivate }
begin
if (theInput <> nil) then { See if there is already a TE area }
TEDeactivate(theInput); { Yes, so turn it off }
theInput := nil; { Deactivate the TE area }
end
else
begin
end;
U_ActivateFloating_window(theWS,Do_An_Activate); { Call the user window activate routine }
SetPort(SavePort); { Restore the old port }
end;
end;
{ ======================================================= }
{ Routine: Do_A_Button }
{ Purpose: Handle a button pressed }
procedure Do_A_Button(theWS:Floating_windowPRec;theControl:ControlHandle); { Handle a button being pressed }
var
RefCon:longint; { RefCon for controls }
UnHiliteValue:integer; { For unhilite }
theSelection:integer; { For palettes and popups }
begin
if (theWS <> nil) then { Only do if the window is us }
begin
HiliteControl(theControl,10); { Darken the button }
UnHiliteValue := 0; { To lighten the button }
RefCon := GetCRefCon(theControl); { get control refcon }
case (RefCon) of { Select correct button }
-1:begin end;
ResC_Tool_palette2: { Tool palette, Tool palette }
begin
theWS^.Value_Tool_palette2 := GetCtlValue(theWS^.Ctrl_Tool_palette2);{ Get the palette value, 0xrrcc, rr is row, cc is column }
end;
otherwise { allow other buttons, trap for debug }
begin
end; { end of otherwise }
end; { end of switch }
U_DoButtonFloating_window(theWS,RefCon,theControl,UnHiliteValue);{ Call to handle any extra user buttons }
HiliteControl(theControl,UnHiliteValue); { Lighten the button }
end;
end; { End of Handle a button being pressed }
{ ======================================================= }
{ Routine: Do_Floating_window }
{ Purpose: Handle action to our window, like controls }
procedure Do_Floating_window(var myEvent:EventRecord);
var
code:integer; { Location of event in window or controls }
whichWindow:WindowPtr; { Window pointer where event happened }
myPt:Point; { Point where event happened }
theControl:ControlHandle; { Handle for a control }
theWS:Floating_windowPRec;
begin
theWS := nil;
code := FindWindow(myEvent.where,whichWindow); { Get where in window and which window }
LocateInstance(whichWindow);
if (RecPtr_Floating_window <> nil) then { Only do if the window is us }
begin
theWS := RecPtr_Floating_window;
U_DoEventFloating_window(theWS,myEvent);
if (myEvent.what = mouseDown) then
begin
myPt := myEvent.where; { Get mouse position }
GlobalToLocal(myPt); { Make it relative }
end;
if ((theWS^.theWindow = whichWindow) and (code = inContent)) then { for our window }
begin
myPt := myEvent.where; { Get mouse position }
GlobalToLocal(myPt); { Make it relative }
code := FindControl(myPt,whichWindow,theControl); { Get type of control }
if (code <> 0) then { Check type of control }
code := TrackControl(theControl,myPt,ProcPtr(-1));{ Track the control }
if (code = inButton) then
Do_A_Button(theWS,theControl); { Do buttons }
end;
end;
end;
{ ======================================================= }
{ ======================================================= }
end.